﻿using IOP.SgrA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample117;

public class ExpandAnimation : Animation
{
    private ITexture? Texture;
    private float operatorT = 1;
    public float uFatFactor { get; private set; }


    public override void Play(TimeSpan timeSpan)
    {
        uFatFactor += operatorT * (float)timeSpan.TotalSeconds * 2.5f;
        if (uFatFactor > 20)
        {
            uFatFactor = 20;
            operatorT = -operatorT;
        }
        Texture?.UpdateTextureMemoryData(uFatFactor);
    }

    public override void CloneToNewRender(IRenderObject newObj)
    {
        var f = new ExpandAnimation();
        f.Name = Name;
        newObj.AddComponent(f);
        f.OnAttach(newObj);
    }

    public override void OnAttach(IRenderObject @object)
    {
        RenderObject = @object;
        Texture = RenderObject.GetComponents<ITexture>().Where(x => x.SetIndex == 0 && x.Binding == 0).FirstOrDefault();
    }
}
